/*
 * @Description: 
 * @Author: cy2020
 * @Date: 2022-02-25 09:05:33
 * @LastEditTime: 2022-02-25 20:11:01
 */
const MQTT = require('./index/MQTT.js');
const WS = require('./index/WS.js');
const TCP = require('./index/TCP.js');

let iot = {
    device: (config, callback) => {
       const { connectUrl } = config
       const protocol = new URL(connectUrl).protocol
       if (protocol === 'mqtt:' || protocol === 'mqtts:') {
        return new MQTT(config, callback);
       } else if (protocol === 'ws:' || protocol === 'wss:') {
        return new WS(config, callback);
       } else if (protocol === 'tcp:' || protocol === 'tls:') {
        return new TCP(config, callback);
       }
    }
};
module.exports = iot;
